package com.qf.Listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * author:z
 * time:2021/12/17 16:09
 * description:
 */
@Component
@RabbitListener(queues = "boot-queue2")
public class QueueListener2 {

    @RabbitHandler
    public void onMessage(String msg, Channel channel, Message message){
        System.out.println("message=====2:"+msg);
//        try {
//            int i=1/0;
//            //参数1：消息的唯一标识
//            //参数2：是否开启批量处理
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
//        }catch (Exception e){
//            e.printStackTrace();
//            //参数1：消息的唯一标识
//            //参数2：失败后当前消费着是否拒绝
//            //参数3：是否回到原队列
//            try {
//                channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
//            } catch (IOException e1) {
//                e1.printStackTrace();
//            }
//        }
    }
}
